<template>
	<view>
		<z-nav-bar v-if="!isWxBrowser" backState="2000" title="我的"></z-nav-bar>
		<view class="page">
			<view class="padding bg-white">
				<view class="flex align-center justify-between">
					<view class="info flex align-center">
						<view class="headimg">
							<image v-if="userInfo.avatar" :src="userInfo.avatar"  mode=""></image>
							<image v-else src="../../static/icon/8c9837cff377d0c4b77e5d6f21f1d6d.png"  mode=""></image>
							<!-- #ifdef MP-WEIXIN -->
							<!-- <open-data type="userAvatarUrl" <v-else></v-else></open-data> -->
							<!-- #endif -->
						</view>
						<view class="margin-left">
							<view class="nickname">
								<text v-if="userInfo.nickname" >{{ userInfo.nickname || '请登录'}}</text>
								<!-- #ifdef MP-WEIXIN -->
								<open-data type="userNickName" v-else></open-data>
								<!-- #endif -->
							</view>
							<view class="">
								真心交友，非诚勿扰～
							</view>
						</view>
					</view>
					<!-- #ifdef MP-WEIXIN || APP-PLUS -->
					<view class="flex align-center" @click="scan" v-if="userInfo.is_admin == 1">
						<image style="width: 50rpx;height: 50rpx;margin-right: 10rpx;" :src=" imgUrl + 'static/web/icon/266c4bc575691365f77f1ddf1db960c.png'" mode=""></image>
					</view>
					<!-- #endif -->
				</view>
				<view class="flex justify-between text-center padding-lr">
					<view class="" @click="onPageJump('/pages/my/collection/collection')">
						<view class="val"> {{ collectionData.my_like_num || 0 }} </view>
						<view class="des"> 我的收藏 </view>
					</view>
					<view class="" @click="onPageJump('/pages/my/like_me/like_me')">
						<view class="val"> {{ collectionData.like_me || 0 }} </view>
						<view class="des"> 喜欢我的 </view>
					</view>
					<view class="" @click="onPageJump('/pages/my/recharge/recharge')">
						<view class="val"> {{ userInfo.virtual_currency_balance || 0 }} </view>
						<view class="des"> 充值红心 </view>
					</view>
				</view>
				<view class="vipbox">
					<image :src=" imgUrl + 'static/web/img/mychongzhi20220324.png'" mode=""></image>
					<view class="vipbox-btn" @click="onPageJump('/pages/my/open_vip/open_vip')"></view>
				</view>
				<view class="toolbox">
					<view class="title">
						常用功能
					</view>
					<view class="flex justify-between padding-sm">
						<view class="tool-item" v-for="(item,index) in tool" :key="index" @click="onPageJump(item.path)" v-if="item.isshow">
							<view class="icon">
								<image :src="item.icon" mode=""></image>
							</view>
							<view class="name">
								{{item.name}}
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="fun bg-white">
				
				<view class="item" @click="onPageJump('/pages/my/auth/auth')">
					<image class="icon" :src=" imgUrl + 'static/web/icon/f8db1baef64c04ec8b78cad1a7e2918.png'" mode=""></image>
					<view class="title">
						实名认证
					</view>
				</view>
				<view class="item" @click="onPageJump('/pages/release/my_message/my_message')">
					<image class="icon" src="../../static/icon/tab/push_c.png" mode=""></image>
					<view class="title">
						完善资料
					</view>
				</view>
				<view class="item" @click="onPageJump('/pages/feedback/feedback')">
					<image class="icon" :src=" imgUrl + 'static/web/img/my/fk.png'" mode=""></image>
					<view class="title">
						留言反馈
					</view>
				</view>
				<!-- #ifdef MP-WEIXIN -->
				<view class="item" @click="subscribe">
					<image class="icon" :src=" imgUrl + 'static/web/icon/043a2eba3379115b92b7de308971ae1.png'" mode=""></image>
					<view class="title">
						订阅消息
					</view>
				</view>
				<view class="item" >
					<image class="icon" :src=" imgUrl + 'static/web/img/my/kf.png'" mode=""></image>
					<button class="title" open-type="contact">联系客服</button>
				</view>
				<!-- #endif -->
				<view class="item" @click="onPageJump('/pages/my/about_us/about_us')">
					<image class="icon" :src=" imgUrl + 'static/web/img/my/about_us.png'" mode=""></image>
					<view class="title">
						关于我们
					</view>
				</view>
			</view>
			
		</view>
		
		<!-- <open-data type="userAvatarUrl"></open-data>
		<open-data type="userNickName"></open-data> -->
		<!-- 公共组件-每个页面必须引入 -->
		<public-module></public-module>
		<!-- #ifdef MP-WEIXIN -->
		<tab-bar :current="4"></tab-bar>
		<!-- #endif -->
	</view>
</template>

<script>
import { mapState, mapMutations } from 'vuex';
export default {
	data() {
		return {
			imgUrl: this.$http.baseUrl, // 服务器域名
			tool:[
				{name:'我的礼物',icon:'https://dating.mync.xyz/static/web/img/my/gift.png',path:'/pages/my/gift/gift',isAuth:true,isshow:true},
				{name:'申请红娘',icon:'https://dating.mync.xyz/static/web/img/my/matchmaker.png',path:'/pages/my/apply/apply',isAuth:true,isshow:true},
				{name:'红娘团队',icon:'https://dating.mync.xyz/static/web/img/my/matchmaker.png',path:'',isAuth:true,isshow:false},
				{name:'推广中心',icon:'https://dating.mync.xyz/static/web/img/my/promote.png',path:'/pages/my/promotion_center/promotion_center',isAuth:true,isshow:true},
				{name:'我的活动',icon:'https://dating.mync.xyz/static/web/img/my/activity.png',path:'/pages/my/activity/activity',isAuth:true,isshow:true},
			],
			collectionData: [], // 我收藏的
		};
	},
	computed: {
		...mapState(['userInfo'])
	},
	onLoad(e) {
		
	},
	onShow() {
		uni.$emit('updateData', {})
		// 检测授权 
		this.judgeLogin(()=>{
			// 获取用户头像
			if(!this.userInfo.avatar){
				this.setBindUserInfoShow(true)
			}
			this.$http.get('api/Member/view').then(res=>{
				this.setUserInfo(res)
				if(res.is_matchmaker == 1){
					this.tool[1].isshow = false
					this.tool[2].isshow = true
					this.tool[2].path = '/pages/home/matchmaker_user/matchmaker_user?user_id=' + this.userInfo.uid
				}
				
			})
			this.getCollection()
		});
		
	},
	//方法
	methods: {
		...mapMutations(['setUserInfo', 'setBindUserInfoShow']),
		onPageJump(url) {
			if(url == '/pages/my/apply/apply'){
				if(this.userInfo.is_auth != '1'){
					uni.showModal({
						title: '提示',
						content: '请先实名认证',
						success:res=>{
							if(res.confirm){
								uni.navigateTo({
									url: '/pages/my/auth/auth'
								})
							}
							if(res.cancel){
								
							}
						}
					})
					return false
				}
			}
			uni.navigateTo({
				url: url
			});
		},
		// 订阅消息
		subscribe(){
			var that = this
			that.$http.get('api/SysSite/index').then(res=>{
				if(res){
					uni.requestSubscribeMessage({
					  tmplIds: [res.list[0].gift_template_id,res.list[0].chat_template_id],
					  success (res) {
						  console.log(res)
					  }
					})
				}
			})
			
		},
		scan(){
			console.log(1234)
			uni.scanCode({
				onlyFromCamera:false,
				scanType: ['qrCode'],
				success(e) {
					uni.navigateTo({
						url:'/pages/my/write_off/write_off?orderno='+e.result
					})
				},
				fail(err) {
					console.log(err)
				}
			})
		},
		// 获取收藏信息
		getCollection(){
			var that = this
			that.$http.get('api/ZhCollection/getLike').then(res=> {
				if(res){
					that.collectionData = res
				}
			})
		}
		
	},
	//页面下来刷新
	onPullDownRefresh() {},
	//页面上拉触底
	onReachBottom() {},
	//用户点击分享
	onShareAppMessage(e) {
		return this.wxShare();
	}
};
</script>
<style lang="scss" scoped>
@import '@/style/mixin.scss';

.page{
	// #ifdef MP-WEIXIN
	padding-bottom: 200rpx;
	// #endif
	.info{
		margin-bottom: 60rpx;
		.headimg{
			width: 120rpx;
			height: 120rpx;
			
			image{
				width: 100%;
				height: 100%;
				border-radius:50%;
			}
		}
		
		.nickname{
			font-size: 28rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: #000013;
			margin-bottom:16rpx ;
		}
	}
	
	.val{
		font-size: 40rpx;
		font-family: WeChat-Sans-Std-Medium, WeChat-Sans-Std;
		font-weight: 500;
		color: #000000;
		margin-bottom: 16rpx;
	}
	.des{
		font-size: 28rpx;
		font-family: PingFangSC-Light, PingFang SC;
		font-weight: 400;
		// color: #6A6A7E;
		color: #000013;
	}
	
	.vipbox{
		position: relative;
		width: 690rpx;
		height: 138rpx;
		margin: 40rpx 0;
		image{
			width: 100%;
			height: 100%;
		}
		.vipbox-btn {
			position: absolute;
			top: 45rpx;
			right: 48rpx;
			width: 142rpx;
			height: 50rpx;
			border-radius: 30rpx;
		}
	}
	.toolbox{
		.title{
			font-size: 32rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: #000013;
			margin-bottom: 38rpx;
		}
		
		.tool-item{
			display: flex;
			flex-direction: column;
			align-items: center;
			.icon{
				width: 60rpx;
				height: 60rpx;
				text-align: center;
				margin-bottom: 20rpx;
				image{
					width: 100%;
					height: 100%;
				}
			}
			.name{
				font-size: 28rpx;
				font-family: PingFangSC-Light, PingFang SC;
				font-weight: 400;
				color: #000000;
			}
		}
	}
	.fun{
		// padding: 30rpx;
		margin: 30rpx 0;
		.item{
			display: flex;
			align-items: center;
			padding: 30rpx;
			border-bottom: 1px solid #F9F9F9;
			.icon{
				width: 40rpx;
				height: 40rpx;
			}
			.title{
				margin-left: 30rpx;
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #36374C;
			}
		}
		.item:nth-child(5){
			padding: 17rpx 30rpx;
		}
	}
}
</style>
